﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using SpaceShooter.GameObjects;

namespace SpaceShooter.Screens
{
    public class StartScreen : IGameScreen
    {
        private BaseGame game;
        private SpriteBatch spriteBatch;
        private SpriteFont font;
        private KeyboardState lastKeyState;
        private GameExitController gameExitController;

        public StartScreen(BaseGame game)
        {
            this.game = game;
        }

        public ICamera DefaultCamera
        {
            get { return null; }
        }

        public void Initialize()
        {
            this.lastKeyState = Keyboard.GetState();
            this.gameExitController = new GameExitController();
        }

        public void LoadContent()
        {
            this.spriteBatch = new SpriteBatch(this.game.GraphicsDevice);

            this.font = this.game.Content.Load<SpriteFont>(@"Fonts\nasalization");
        }

        public void UnloadContent()
        {
        }

        public void Render(GameTime gameTime)
        {
            this.spriteBatch.Begin();

            this.spriteBatch.DrawString(
                this.font, 
                "Press SPACE to enter game", 
                new Vector2(10, 10), 
                Color.White);
            
            this.spriteBatch.End();
        }

        public void Update(GameTime gametime)
        {
            var state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.Space) && !this.lastKeyState.IsKeyDown(Keys.Space))
            {
                this.game.AddScreen(new GameScreen(this.game));
            }

            if (gameExitController.CheckExitGame())
            {
                this.game.ExitScreen();
            }

            this.lastKeyState = state;
        }

        public Game Game
        {
            get { return this.game; }
        }

        public GameField GameField
        {
            get { throw new NotImplementedException(); }
        }
    }
}
